package shthon2011s.eroid;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class DenshaActivity extends Activity {
    public static final String STEPS = "shthon2011s.eroid.DenshaActivity.STEPS";
    public static final String CALORIE = "shthon2011s.eroid.DenshaActivity.CALORIE";

    private TextView info;
    private ImageView train;
	private Handler mHandler;
	private int pos = 0, max;
	private Runnable anim = new Runnable(){
		@Override
		public void run() {
	        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)train.getLayoutParams();
	        params.rightMargin = pos;
	        train.setLayoutParams(params);
	        pos += 2;
	        if(pos < max){
	    		mHandler.postDelayed(anim, 25);
	        }
		}
	};

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.densha);
        info = (TextView)findViewById(R.id.textView1);
        train = (ImageView)findViewById(R.id.imageView1);
		mHandler = new Handler();

        //前画面から歩数のパラメタを受け取る
        int steps = 0;
        float calorie = 0;
        Bundle extras = getIntent().getExtras();
		if(extras != null){
			//引数あり(通常起動用)
			steps = extras.getInt(STEPS);
			calorie = extras.getFloat(CALORIE);
		}

        //画面に表示
        info.setText(String.format("みんなありがとう！！\n今日の成果は%d歩\n%.2fキロカロリー", steps, calorie));
        pos = 0;
        max = 380;	//TODO calc
		mHandler.postDelayed(anim, 1000);
    }
}
	//TODO 電車を動かす
//TODO 画像を差し替える